<?php

require_once dirname(__FILE__) . '/TestCase.php';

class Auth_Vidoop_Secure_CaptchaAPITest extends Auth_Vidoop_Secure_TestCase {

	public function testAPICall() {
		$service = $this->get_service('captcha');
		$captcha = $service->new_captcha( 
			array( 'height' => 2, 'width' => 7, 'order_matters' => true, 'captcha_length' => 4)
		);

		$this->assertEquals(4, $captcha->captcha_length);
		$this->assertNotNull($captcha->id);
		$this->assertTrue($captcha->order_matters);
		$this->assertEquals(2, $captcha->height);
		$this->assertEquals(7, $captcha->width);
		$this->assertNotNull($captcha->text);
		$this->assertEquals($this->config['base'] . '/vs/captchas/' . $captcha->id . '/image', $captcha->image);
		$this->assertFalse($captcha->attempted);
		$this->assertFalse($captcha->authenticated);

		// attempt code verification
		$verify_result = $service->verify_code($captcha->id, 'a');
		$this->assertFalse($verify_result);

		// see that verify attempt has been recorded
		$captcha2 = $service->get_captcha($captcha->id);
		$this->assertEquals($captcha->id, $captcha2->id);
		$this->assertTrue($captcha2->attempted);
	}

}
